package com.chuanyang.driverh.mainother;


import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseTitleActivity;
import com.chuanyang.driverh.utils.SharedPrefUtil;

public class StrategyActivity extends BaseTitleActivity {

    private ImageView iv_strategy_congestion;
    private ImageView iv_strategy_cost;
    private ImageView iv_strategy_hightspeed;
    private ImageView iv_strategy_direct;
    private boolean isCongestion;
    private boolean isCost;
    private boolean isHightspeed;
    private boolean isDirect;
    private boolean isAvoidhightspeed;
    private ImageView iv_strategy_avoidspeed;

    @Override
    protected int getContentResId() {
        return R.layout.other_act_strategy;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        //躲避拥堵
        iv_strategy_congestion = (ImageView) findViewById(R.id.iv_strategy_congestion);
        //避免收费
        iv_strategy_cost = (ImageView) findViewById(R.id.iv_strategy_cost);
        //高速优先
        iv_strategy_hightspeed = (ImageView) findViewById(R.id.iv_strategy_hightspeed);
        //不走高速
        iv_strategy_avoidspeed = (ImageView) findViewById(R.id.iv_strategy_avoidspeed);
        //直接导航
        iv_strategy_direct = (ImageView) findViewById(R.id.iv_strategy_direct);
    }

    @Override
    public void initData() {
        setBackImg();
        getTitleTextView().setText("策略设置");
        fillView();

    }

    @Override
    protected void initListener() {
        iv_strategy_congestion.setOnClickListener(this);
        iv_strategy_cost.setOnClickListener(this);
        iv_strategy_hightspeed.setOnClickListener(this);
        iv_strategy_avoidspeed.setOnClickListener(this);
        iv_strategy_direct.setOnClickListener(this);
    }

    private void fillView() {
        //避免拥堵
        isCongestion = SharedPrefUtil.isCongestion();
        //避免收费
        isCost = SharedPrefUtil.isCost();
        //高速优先
        isHightspeed = SharedPrefUtil.isHightspeed();
        //不走高速
        isAvoidhightspeed = SharedPrefUtil.isAvoidhightspeed();
        //直接导航
        isDirect = SharedPrefUtil.isDirect();
        iv_strategy_congestion.setSelected(isCongestion);
        iv_strategy_cost.setSelected(isCost);
        iv_strategy_hightspeed.setSelected(isHightspeed);
        iv_strategy_direct.setSelected(isDirect);
        iv_strategy_avoidspeed.setSelected(isAvoidhightspeed);

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_strategy_congestion:
                resetAll();
                if (iv_strategy_congestion.isSelected()) {
                    iv_strategy_congestion.setSelected(false);
                    SharedPrefUtil.setisCongestion(false);
                } else {
                    iv_strategy_congestion.setSelected(true);
                    SharedPrefUtil.setisCongestion(true);
                }

                break;
            case R.id.iv_strategy_cost:
                resetAll();
                if (iv_strategy_cost.isSelected()) {
                    iv_strategy_cost.setSelected(false);
                    SharedPrefUtil.setisCost(false);
                } else {
                    iv_strategy_cost.setSelected(true);
                    SharedPrefUtil.setisCost(true);
                }

                break;
            case R.id.iv_strategy_hightspeed:
                resetAll();
                if (iv_strategy_hightspeed.isSelected()) {
                    iv_strategy_hightspeed.setSelected(false);
                    SharedPrefUtil.setisHightspeed(false);
                } else {
                    iv_strategy_hightspeed.setSelected(true);
                    SharedPrefUtil.setisHightspeed(true);
                }
                break;
            case R.id.iv_strategy_direct:
                if (iv_strategy_direct.isSelected()) {
                    iv_strategy_direct.setSelected(false);
                    SharedPrefUtil.setisDirect(false);
                } else {
                    iv_strategy_direct.setSelected(true);
                    SharedPrefUtil.setisDirect(true);
                }
                break;
            case R.id.iv_strategy_avoidspeed:
                resetAll();
                if (iv_strategy_avoidspeed.isSelected()) {
                    iv_strategy_avoidspeed.setSelected(false);
                    SharedPrefUtil.setisAvoidhightspeed(false);
                }
                else {
                    iv_strategy_avoidspeed.setSelected(true);
                    SharedPrefUtil.setisAvoidhightspeed(true);
                }
                break;
        }
    }

    private void resetAll() {
        iv_strategy_congestion.setSelected(false);
        SharedPrefUtil.setisCongestion(false);
        iv_strategy_cost.setSelected(false);
        SharedPrefUtil.setisCost(false);
        iv_strategy_hightspeed.setSelected(false);
        SharedPrefUtil.setisHightspeed(false);
        iv_strategy_avoidspeed.setSelected(false);
        SharedPrefUtil.setisAvoidhightspeed(false);
    }

}
